﻿using System;
using System.Web;
using Enyim.Caching;
using Web.Controllers;
using Web.ActionFilters;
using SilenthinkContract;
using System.Configuration;
using SilenthinkContract.Component;

namespace Web.Areas.My.Controllers
{
    [SkAuthorize]
    public abstract class MyBaseController : BaseController
    {
        protected static readonly string AesKey = ConfigurationManager.AppSettings["Aes.Key"];
        protected static readonly string PasswordSalt = ConfigurationManager.AppSettings["Password.Salt"];


        protected MyBaseController(ILogService logService, IBaseService baseService, IExtraService extraService, IStoreService storeService, IOrderService orderService, IGameService gameService, IAuctionService auctionService, IPassportService passportService, IPaymentService paymentService, IMemcachedClient memcachedClient) : base(logService, baseService, extraService, storeService, orderService, gameService, auctionService, passportService, paymentService, memcachedClient)
        {
        }

        protected bool SaveAvatar(long userId, AvatarSize avatar, HttpPostedFileBase postedFile)
        {
            var result = false;
            var fileName =string.Format("~/avatar/avatar.{0}.{1}.jpg", userId, avatar.GetSize());
            try
            {
                if (postedFile != null)
                {
                    postedFile.SaveAs(Server.MapPath(fileName));
                    result = true;
                }
            }
            catch (Exception)
            {
                result = false;
            }
            return result;
        }
    }
}
